import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

import Layout from '@/layout';

export const constantRoutes = [

  // 默认页面
  {
    path: '/login',
    component: () =>
      import ('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () =>
      import ('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () =>
        import ('@/views/Home/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  // 内容管理
  {
    path: '/TeaTreeManagement',
    component: Layout,
    meta: { title: '内容管理', icon: 'dashboard' },
    children: [
      {
        path: 'Dynamic',
        name: 'Dynamic',
        component: () =>
          import ('@/views/Dynamic/list'),
        meta: { title: '动态管理', icon: 'dashboard' }
      },
      {
        path: 'Match',
        name: 'Match',
        component: () =>
          import ('@/views/Match/list'),
        meta: { title: '匹配管理', icon: 'dashboard' }
      },
      {
        path: 'Word',
        name: 'Word',
        component: () =>
          import ('@/views/Word/list'),
        meta: { title: '单词管理', icon: 'dashboard' }
      }
    ]
  },
  // 系统配置
  // {
  //   roles: ['admin'],
  //   path: '/System',
  //   component: Layout,
  //   meta: { title: '系统设置', icon: 'dashboard' },
  //   children: [{
  //     path: 'QRcode',
  //     name: 'QRcode',
  //     component: () =>
  //       import ('@/views/System/index'),
  //     meta: { title: '二维码路径', icon: 'dashboard' }
  //   },
  //   {
  //     path: 'SystemOther',
  //     name: 'SystemOther',
  //     component: () =>
  //       import ('@/views/System/other'),
  //     meta: { title: '其他', icon: 'dashboard' }
  //   }
  //   ]
  // },
  // 用户管理
  {
    path: '/User',
    component: Layout,
    roles: ['admin'],
    meta: { title: '用户管理', icon: 'dashboard' },
    children: [{
      path: 'list',
      name: 'list',
      component: () =>
        import ('@/views/User/list'),
      meta: { title: '用户管理', icon: 'dashboard' }
    }]
  },

  // 不存在的页面跳转404页面
  { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
